/*
 * CommonMethod.java
 *
 * Created on 2007年4月24日, 下午4:48
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.ecomm.util;

import com.pphome.orgmodel.manager.OrgManager;
import com.pphome.orgmodel.manager.UserManager;
import com.pphome.orgmodel.pojo.OrgInfo;
import com.pphome.orgmodel.pojo.UserInfo;
import java.util.*;



/**
 *
 * @author pijunliang
 */
public class CommonMethod {
  
  /** Creates a new instance of CommonMethod */
  public CommonMethod() {
  }
  /**
   *新增这里一个MAP，对应页面chat/message/search.jsp就要多加一个事件，详细请看页面
   *
   */
  public static Map<String,String> bigtype = new HashMap();
  public static Map<String,String> unInterfacetype = new HashMap();
  public static Map<String,String> Interfacetype = new HashMap();
  static {
    bigtype.put("1","收文管理");
    bigtype.put("2","私聊");
    bigtype.put("3","发文管理");
    bigtype.put("4","通知");
    
    unInterfacetype.put("1","单聊");
    unInterfacetype.put("2","群聊");
    
    Interfacetype.put("1","未收单");
    Interfacetype.put("2","发送");
  }
  public static String getType(String bigtype,String type){
    if(bigtype == null || type == null ){
      return null;
    }
    if(bigtype.equals("1")){
      return Interfacetype.get(type);
    }else if(bigtype.equals("2")){
      return unInterfacetype.get(type);
    }else{
      return "其他";
    }
  }
  
  public static String getUserNameByUserID(String user_id) {
    if (user_id == null || user_id.equals("")) {
      return null;
    }
    String username = "";
    UserInfo ui = UserManager.getInstance().getUserInfoById(user_id);
    if(ui != null){
      username = ui.getName();
    }
    return username;
  }
  
  /**
   * 通过机构ID得到机构的名字
   *
   */
  public static String getOrgNameByOrgID(String org_id) {
    if (org_id == null || org_id.equals("")) {
      return null;
    }
    String orgName = "";
    OrgInfo oi = OrgManager.getInstance().getOrgInfoById(org_id);
    if(oi != null){
      orgName = oi.getName();
    }
    return orgName;
  }
  
  /**
   * 通过当前用户id，得到用户最直接的部门名称
   *
   */
  public static String getOrgNameByUserID(String userid) {
    if (userid == null || userid.equals("")) {
      return null;
    }
    String orgName = "";
    UserInfo ui = UserManager.getInstance().getUserInfoById(userid);
    if(ui != null){
      OrgInfo oi =  ui.getOrgInfo();
      if(oi  != null){
        orgName = oi.getName();
      }
    }
    System.out.println("orgname ---------"+orgName);
    return orgName;
  }
  /**
   *根据用户ID查出所有用户，这里的 ID是 "123,1234,1234,12341,1234,"
   */
  public static String getUsernamesByUserids(String userids){
    if(userids == null || userids.equals("")){
      return null;
    }
    StringBuilder sb = new StringBuilder();
    String[] userid = userids.split(",");
    for (int i = 0; i < userid.length; i++) {
      sb.append(getUserNameByUserID(userid[i]));
      sb.append(",");
    }
    return sb.toString();
  }
  
}
